package org.springframework.social.showcase.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.social.twitter.api.Tweet;
import org.springframework.stereotype.Repository;



@Repository
public class TweetSearchService {
	@Autowired
	private MongoTemplate mongoTemplate;
	
	public void setMongoTemplate(MongoTemplate mongoTemplateServ)
	{
		mongoTemplate=mongoTemplateServ;
	}
	public static final String COLLECTION_NAME = "tweet";
	
	public void addTweet(Tweet tweet) {
		if (!mongoTemplate.collectionExists(Tweet.class)) {
			mongoTemplate.createCollection(Tweet.class);
		}		
		System.out.println(tweet);
		mongoTemplate.insert(tweet, COLLECTION_NAME);
	}
	
	public List<Tweet> listTweet() {
		return mongoTemplate.findAll(Tweet.class, COLLECTION_NAME);
	}
	
	public void deleteTweet(Tweet tweet) {
		mongoTemplate.remove(tweet, COLLECTION_NAME);
	}
	
	public void updateTweet(Tweet tweet) {
		mongoTemplate.insert(tweet, COLLECTION_NAME);		
	}
	
	public void updateTweetALL(List<Tweet> tweetList) {
		mongoTemplate.insert(tweetList, COLLECTION_NAME);		
	}
}
